<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>随机生成指定长度的字符串</title>
    <script>
        function randomString(n) {
            var str = getLetters()
            var newStr = ''
            for (var i = 0; i < n; i++) {
                newStr += str.charAt(Math.floor(Math.random() * str.length))
            }
            return newStr
        }

        function getLetters() {
            var str = ''
            for (var i = 0; i < 26; i++) {
                str += String.fromCharCode(97 + i)
            }
            return str
        }

        console.log(randomString(3))
    </script>
</head>

<body>

</body>

</html>